package com.quiz.bis.controller;

import com.quiz.bis.domain.bo.PaperGenerateRequest;
import com.quiz.bis.domain.vo.PaperGenerateResult;
import com.quiz.bis.service.IPaperGenerateService;
import com.quiz.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 组卷控制器
 */
@RestController
@RequestMapping("paper2/generate")
@Tag(name = "试卷生成")
@RequiredArgsConstructor
public class PaperGenerateController {

    private final IPaperGenerateService paperGenerateService;

    /**
     * 自动组卷
     */
    @PostMapping
    public R<PaperGenerateResult> generatePaper(@Validated @RequestBody PaperGenerateRequest request) {
        PaperGenerateResult result = paperGenerateService.autoGeneratePaper(request);
        return result.getSuccess() ? R.ok(result) : R.fail(result.getMessage());
    }

    /**
     * 固定系数组卷
     */
    @PostMapping("template")
    public R<PaperGenerateResult> templateGenerate(@Validated @RequestBody PaperGenerateRequest request) {
        PaperGenerateResult result = paperGenerateService.templateGeneratePaper(request);
        return result.getSuccess() ? R.ok(result) : R.fail(result.getMessage());
    }

    /**
     * 遗传算法组卷
     */
    @PostMapping("genetic")
    public R<PaperGenerateResult> geneticGenerate(@Validated @RequestBody PaperGenerateRequest request) {
        PaperGenerateResult result = paperGenerateService.geneticGeneratePaper(request);
        return result.getSuccess() ? R.ok(result) : R.fail(result.getMessage());
    }
}